#!/bin/bash
#
# rail patch from 1.0 to 1.1
#
version=2008-04-10

MYSQL_RUN="/usr/bin/mysql"

set -e

# some constant values
TIMESTAMP=`date "+%s"`
USAGE="Usage: rail_1.0to1.1.sh [-h -u -p] DATABASES"
MYSQL_OPT=""

# info
echo "rail_1.0to1.1 Ver $version RAIL Ver $RAIL_VERSION, using mysql command line tool"
echo "Copyright (C) 2008 Bastian Schröder"
echo "This software comes with ABSOLUTELY NO WARRANTY. This is free software,"
echo "and you are welcome to modify and redistribute it under the GPL license"

# options
while getopts ":h:u:p:" optname ; do
	case "$optname" in
		"h")
			MYSQL_OPT="$MYSQL_OPT -h $OPTARG"
			;;
		"u")
			MYSQL_OPT="$MYSQL_OPT -u $OPTARG"
			;;
		"p")
			MYSQL_OPT="$MYSQL_OPT --password=$OPTARG"
			;;
		"?")
			echo "Unknown option $OPTARG"
			echo $USAGE
			exit 1
			;;
		":")
			echo "No argument value for option $OPTARG"
			echo $USAGE
			exit 1
			;;
		*)
			# Should not occur
			echo "Unknown error while processing options"
			echo $USAGE
			exit 1
			;;
	esac
done
if [ $OPTIND -gt 1 ] ; then
	shift $(($OPTIND - 1))
fi

# script parameter
if [ $# -lt 2 ] ; then
	echo $USAGE
	exit 1
else
	DATABASES=$1
fi